package com.xzx.shop_front_api.controller;

import com.google.gson.Gson;
import com.qiniu.util.Json;
import com.xzx.shop_front_api.entity.Messages;
import com.xzx.shop_front_api.producer.RabbitMQProducer;
import com.xzx.shop_front_api.service.MessageService;
import com.xzx.shop_front_api.utils.JsonResult;
import com.xzx.shop_front_api.utils.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("mq")
public class RabbitMQController {
    @Autowired
    private RabbitMQProducer rabbitMQProducer;
    @Autowired
    private MessageService messageService;
    @PostMapping("send")
    public JsonResult sendMessage(@RequestBody Messages message) {
        Gson gson = new Gson();
        message.setCreatedTime(Tool.getCurrentTime());
        String strMessage = gson.toJson(message);
        rabbitMQProducer.sendMessage(strMessage);
        return JsonResult.success("ok",null);
    }
}
